<?php

namespace App\Http\Controllers\Admin;

use App\Http\Requests\PermissionRequest;
use App\Models\Permission;
use Auth;

class PermissionsController extends Controller
{
    public function index()
    {
        return Permission::orderBy('sort')->orderBy('id')->get();
    }

    public function store(PermissionRequest $request)
    {
        $permission = Permission::create($request->only('pid', 'title', 'name', 'sort', 'icon', 'type', 'status'));
        return $permission;
    }

    public function edit(Permission $permission)
    {
        return $permission;
    }

    public function update(PermissionRequest $request, Permission $permission)
    {
        $permission->update($request->only('pid', 'title', 'name', 'sort', 'icon', 'type', 'status'));
        return $permission;
    }

    public function destroy(Permission $permission)
    {
        $permission->delete();

        // 关联用户、角色
        $permission->users()->detach();
        $permission->roles()->detach();
    }




}